home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / Src / Ch4 / Rich.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-04-02  |  9.8 KB  |  299 lines

  1. VERSION 5.00
  2. Object = "{3B7C8863-D78F-101B-B9B5-04021C009402}#1.2#0"; "richtx32.ocx"
  3. Begin VB.Form frmRich 
  4.    Caption         =   "Rich"
  5.    ClientHeight    =   4440
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   6165
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   4440
  11.    ScaleWidth      =   6165
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin VB.CommandButton cmdCombine 
  14.       Caption         =   "Combine"
  15.       Height          =   495
  16.       Left            =   3900
  17.       TabIndex        =   12
  18.       Top             =   2160
  19.       Width           =   1215
  20.    End
  21.    Begin VB.Frame Frame1 
  22.       Height          =   2175
  23.       Index           =   1
  24.       Left            =   4560
  25.       TabIndex        =   6
  26.       Top             =   -60
  27.       Width           =   4455
  28.       Begin VB.CheckBox chkBold 
  29.          Caption         =   "Bold"
  30.          Height          =   255
  31.          Index           =   1
  32.          Left            =   120
  33.          TabIndex        =   10
  34.          Top             =   240
  35.          Width           =   975
  36.       End
  37.       Begin VB.CheckBox chkItalic 
  38.          Caption         =   "Italic"
  39.          Height          =   255
  40.          Index           =   1
  41.          Left            =   1200
  42.          TabIndex        =   9
  43.          Top             =   240
  44.          Width           =   975
  45.       End
  46.       Begin VB.CheckBox chkUnderline 
  47.          Caption         =   "Underline"
  48.          Height          =   255
  49.          Index           =   1
  50.          Left            =   2280
  51.          TabIndex        =   8
  52.          Top             =   240
  53.          Width           =   975
  54.       End
  55.       Begin VB.CheckBox chkStrikethru 
  56.          Caption         =   "Strikethru"
  57.          Height          =   255
  58.          Index           =   1
  59.          Left            =   3360
  60.          TabIndex        =   7
  61.          Top             =   240
  62.          Width           =   975
  63.       End
  64.       Begin RichTextLib.RichTextBox rchInput 
  65.          Height          =   1455
  66.          Index           =   1
  67.          Left            =   120
  68.          TabIndex        =   11
  69.          Top             =   600
  70.          Width           =   4215
  71.          _ExtentX        =   7435
  72.          _ExtentY        =   2566
  73.          _Version        =   393217
  74.          TextRTF         =   $"Rich.frx":0000
  75.       End
  76.    End
  77.    Begin VB.Frame Frame1 
  78.       Height          =   2175
  79.       Index           =   0
  80.       Left            =   0
  81.       TabIndex        =   0
  82.       Top             =   -60
  83.       Width           =   4455
  84.       Begin VB.CheckBox chkStrikethru 
  85.          Caption         =   "&Strikethru"
  86.          Height          =   255
  87.          Index           =   0
  88.          Left            =   3360
  89.          TabIndex        =   4
  90.          Top             =   240
  91.          Width           =   975
  92.       End
  93.       Begin VB.CheckBox chkUnderline 
  94.          Caption         =   "&Underline"
  95.          Height          =   255
  96.          Index           =   0
  97.          Left            =   2280
  98.          TabIndex        =   3
  99.          Top             =   240
  100.          Width           =   975
  101.       End
  102.       Begin VB.CheckBox chkItalic 
  103.          Caption         =   "&Italic"
  104.          Height          =   255
  105.          Index           =   0
  106.          Left            =   1200
  107.          TabIndex        =   2
  108.          Top             =   240
  109.          Width           =   975
  110.       End
  111.       Begin VB.CheckBox chkBold 
  112.          Caption         =   "&Bold"
  113.          Height          =   255
  114.          Index           =   0
  115.          Left            =   120
  116.          TabIndex        =   1
  117.          Top             =   240
  118.          Width           =   975
  119.       End
  120.       Begin RichTextLib.RichTextBox rchInput 
  121.          Height          =   1455
  122.          Index           =   0
  123.          Left            =   120
  124.          TabIndex        =   5
  125.          Top             =   600
  126.          Width           =   4215
  127.          _ExtentX        =   7435
  128.          _ExtentY        =   2566
  129.          _Version        =   393217
  130.          TextRTF         =   $"Rich.frx":0133
  131.       End
  132.    End
  133.    Begin RichTextLib.RichTextBox rchOutput 
  134.       Height          =   1455
  135.       Index           =   0
  136.       Left            =   120
  137.       TabIndex        =   13
  138.       Top             =   2880
  139.       Width           =   4215
  140.       _ExtentX        =   7435
  141.       _ExtentY        =   2566
  142.       _Version        =   393217
  143.       ReadOnly        =   -1  'True
  144.       TextRTF         =   $"Rich.frx":0266
  145.    End
  146.    Begin RichTextLib.RichTextBox rchOutput 
  147.       Height          =   1455
  148.       Index           =   1
  149.       Left            =   4680
  150.       TabIndex        =   14
  151.       Top             =   2880
  152.       Width           =   4215
  153.       _ExtentX        =   7435
  154.       _ExtentY        =   2566
  155.       _Version        =   393217
  156.       ReadOnly        =   -1  'True
  157.       TextRTF         =   $"Rich.frx":032F
  158.    End
  159.    Begin VB.Label Label1 
  160.       Alignment       =   2  'Center
  161.       Caption         =   "SelRTF Properties"
  162.       Height          =   255
  163.       Index           =   1
  164.       Left            =   4680
  165.       TabIndex        =   16
  166.       Top             =   2640
  167.       Width           =   4215
  168.    End
  169.    Begin VB.Label Label1 
  170.       Alignment       =   2  'Center
  171.       Caption         =   "SelText Properties"
  172.       Height          =   255
  173.       Index           =   0
  174.       Left            =   120
  175.       TabIndex        =   15
  176.       Top             =   2640
  177.       Width           =   4215
  178.    End
  179. Attribute VB_Name = "frmRich"
  180. Attribute VB_GlobalNameSpace = False
  181. Attribute VB_Creatable = False
  182. Attribute VB_PredeclaredId = True
  183. Attribute VB_Exposed = False
  184. Option Explicit
  185. Private IgnoreChanges As Boolean
  186. ' Set a check box's tri-state value.
  187. Private Sub SetCheck(ByVal chk As CheckBox, ByVal value As Variant)
  188.     IgnoreChanges = True
  189.     If IsNull(value) Then
  190.         chk.value = vbGrayed
  191.     ElseIf value Then
  192.         chk.value = vbChecked
  193.     Else
  194.         chk.value = vbUnchecked
  195.     End If
  196.     IgnoreChanges = False
  197. End Sub
  198. Private Sub chkBold_Click(Index As Integer)
  199.     If IgnoreChanges Then Exit Sub
  200.     rchInput(Index).SelBold = (chkBold(Index).value = vbChecked)
  201. End Sub
  202. ' Set the selection's style.
  203. Private Sub chkItalic_Click(Index As Integer)
  204.     If IgnoreChanges Then Exit Sub
  205.     rchInput(Index).SelItalic = (chkItalic(Index).value = vbChecked)
  206.     rchInput(Index).SetFocus
  207. End Sub
  208. Private Sub chkStrikethru_Click(Index As Integer)
  209.     If IgnoreChanges Then Exit Sub
  210.     rchInput(Index).SelStrikeThru = (chkStrikethru(Index).value = vbChecked)
  211. End Sub
  212. Private Sub chkunderline_Click(Index As Integer)
  213.     If IgnoreChanges Then Exit Sub
  214.     rchInput(Index).SelUnderline = (chkUnderline(Index).value = vbChecked)
  215. End Sub
  216. ' Combine the values in the rchInput controls.
  217. Private Sub cmdCombine_Click()
  218. Dim sel_start(0 To 1) As Integer
  219. Dim sel_length(0 To 1) As Integer
  220. Dim i As Integer
  221.     ' Combine text only.
  222.     rchOutput(0).Text = rchInput(0).Text & _
  223.         vbCrLf & rchInput(1).Text
  224.     ' Save the current SelStart and SelLength values.
  225.     For i = 0 To 1
  226.         sel_start(i) = rchInput(i).SelStart
  227.         sel_length(i) = rchInput(i).SelLength
  228.         rchInput(i).SelStart = 0
  229.         rchInput(i).SelLength = Len(rchInput(i).Text)
  230.     Next i
  231.     ' Combine the text only.
  232.     rchOutput(0).Text = rchInput(0).Text & _
  233.         vbCrLf & rchInput(1).Text
  234.     ' Combine the rich text values.
  235.     ' Copy the first control's text with RTF codes.
  236.     rchOutput(1).SelStart = 0
  237.     rchOutput(1).SelLength = Len(rchOutput(1).Text)
  238.     rchOutput(1).SelRTF = rchInput(0).SelRTF
  239.     ' Add vbCrLf to the end.
  240.     rchOutput(1).SelStart = Len(rchOutput(1).Text)
  241.     rchOutput(1).SelLength = 0
  242.     rchOutput(1).SelText = vbCrLf
  243.     ' Add the second control's text with RTF codes.
  244.     rchOutput(1).SelStart = Len(rchOutput(1).Text)
  245.     rchOutput(1).SelLength = 0
  246.     rchOutput(1).SelRTF = rchInput(1).SelRTF
  247.     ' Restore the SetStart and SelLength values.
  248.     For i = 0 To 1
  249.         rchInput(i).SelStart = sel_start(i)
  250.         rchInput(i).SelLength = sel_length(i)
  251.     Next i
  252.     rchOutput(1).SelLength = 0
  253. End Sub
  254. ' Prepare the program.
  255. Private Sub Form_Load()
  256.     ' Set the form's width.
  257.     Width = Frame1(1).Left + Frame1(1).Width + Width - ScaleWidth
  258.     ' Set some text properties.
  259.     rchInput(0).SelStart = 0
  260.     rchInput(0).SelLength = Len(rchInput(0).Text)
  261.     rchInput(0).SelBold = True
  262.     rchInput(0).SelLength = 0
  263.     rchInput(1).SelStart = 0
  264.     rchInput(1).SelLength = Len(rchInput(1).Text)
  265.     rchInput(1).SelItalic = True
  266.     rchInput(1).SelLength = 0
  267. End Sub
  268. Private Sub rchInput_KeyPress(Index As Integer, KeyAscii As Integer)
  269. Const CTRL_B = 2
  270. Const CTRL_I = 9
  271. Const CTRL_U = 21
  272. Const CTRL_S = 19
  273.     If KeyAscii = CTRL_B Then
  274.         rchInput(Index).SelBold = Not rchInput(Index).SelBold
  275.         KeyAscii = 0
  276.     End If
  277.     If KeyAscii = CTRL_I Then
  278.         rchInput(Index).SelItalic = Not rchInput(Index).SelItalic
  279.         KeyAscii = 0
  280.     End If
  281.     If KeyAscii = CTRL_U Then
  282.         rchInput(Index).SelUnderline = Not rchInput(Index).SelUnderline
  283.         KeyAscii = 0
  284.     End If
  285.     If KeyAscii = CTRL_S Then
  286.         rchInput(Index).SelStrikeThru = Not rchInput(Index).SelStrikeThru
  287.         KeyAscii = 0
  288.     End If
  289.     ' Recheck the check box values.
  290.     If KeyAscii = 0 Then rchInput_SelChange Index
  291. End Sub
  292. ' Set the proper check boxes for the selected text.
  293. Private Sub rchInput_SelChange(Index As Integer)
  294.     SetCheck chkBold(Index), rchInput(Index).SelBold
  295.     SetCheck chkItalic(Index), rchInput(Index).SelItalic
  296.     SetCheck chkUnderline(Index), rchInput(Index).SelUnderline
  297.     SetCheck chkStrikethru(Index), rchInput(Index).SelStrikeThru
  298. End Sub
  299.